/**
 * @class   wosh::interfaces::Device
 * @brief   wosh::interfaces::Device is a sub-class of a generic wosh::interfaces::IBundle,
 *          it represent a generic virtual device or an adapter to a real device.
 *
 * @see     \ref Devices, \ref page_core_bundles
 * @see     wosh::interfaces::devices
 * @ingroup Interfaces
 ****************************************************************************
 * @version 0.8.499 $Id: Device.h 2319 2010-04-21 01:39:52Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Interfaces_Device_H__
 #define __WOSH_Interfaces_Device_H__

 #include <woshDefs.h>
 #include <interfaces/IBundle.h>


namespace wosh {
 namespace interfaces {
  namespace devices { };


class Device : public virtual IBundle
 {
	WOSH_BUNDLE_INTERFACE("wosh::interfaces::Device")
	WOSH_BUNDLE_SINGLETON(0,0)

	public:
		///  states of a device
		enum DEVICE_STATE {
			UNKNOWN		= 0x00,	///< state is unknown, (default during initialization)
			LINKED		= 0x01,	///< device is working and its services are available
			UNLINKED	= 0x02,	///< device is turned off or unavailable, can't provide its services
			BROKEN		= 0x04	///< device is not working properly, sw/hw failure
		 };

	public:
		/**
		 * @brief  Evaluate if the state is \c LINKED. Provided for convenience.
		 * @return true if the state is wosh::interfaces::Device::LINKED; false else
		 */
		inline bool isDeviceLinked() const			{ return (getDeviceState() == wosh::interfaces::Device::LINKED); }
		/**
		 * @brief  Evaluate if the state is \c UNLINKED. Provided for convenience.
		 * @return true if the state is wosh::interfaces::Device::UNLINKED; false else
		 */
		inline bool isDeviceUnLinked() const		{ return (getDeviceState() == wosh::interfaces::Device::UNLINKED); }
		/**
		 * @brief  Evaluate if the state is \c BROKEN. Provided for convenience.
		 * @return true if the state is wosh::interfaces::Device::BROKEN; false else
		 */
		inline bool isDeviceBroken() const			{ return (getDeviceState() == wosh::interfaces::Device::BROKEN); }
		/**
		 * @brief  Get the current device state as literal string. Provided for convenience.
		 * @return C string represeting the current state
		 * @see    Device::getDeviceStateAsString
		 */
		inline const char* getDeviceStateAsString() const	{ return getDeviceStateAsString(getDeviceState()); }

/** @name Device Interface
 * @{
 ******************************************************************************/
	public:
		/**
		 * @brief  Evaluate device's state. Implemented by inherited classes.
		 * @return the current state of Device
		 */
		virtual wosh::interfaces::Device::DEVICE_STATE getDeviceState() const = 0;
//@}
	public:
		/**
		 * @brief   Get device state as a literal string
		 * @param state [in] device state to be retrieved as literal string
		 * @return  passed device state as literal string
		 */
		static const char* getDeviceStateAsString( wosh::interfaces::Device::DEVICE_STATE state ) {
			switch(state) {
				case wosh::interfaces::Device::LINKED:		return "LINKED";
				case wosh::interfaces::Device::UNLINKED:	return "UNLINKED";
				case wosh::interfaces::Device::BROKEN:		return "BROKEN";
				case wosh::interfaces::Device::UNKNOWN:
				default:									return "UNKNOWN";
			 }
		 }
		/**
		 * @brief   Get device state from a literal string
		 * @param state [in] device state as literal string
		 * @return  device state (as enum) associated with the argument 
		 */
		static wosh::interfaces::Device::DEVICE_STATE getDeviceStateFromString( const char* state ) {
			if ( state == NULL ) return wosh::interfaces::Device::UNKNOWN;
			else if ( strcmp(state, "LINKED") == 0 )		return wosh::interfaces::Device::LINKED;
			else if ( strcmp(state, "UNLINKED") == 0 )		return wosh::interfaces::Device::UNLINKED;
			else if ( strcmp(state, "BROKEN") == 0 )		return wosh::interfaces::Device::BROKEN;
			return wosh::interfaces::Device::UNKNOWN;
		 }

	public:
		virtual ~Device() { }

}; // class def

 }; // namespace interfaces
}; // namespace wosh

#endif //__WOSH_Interfaces_Device_H__
